package cn.com.surker.production.service.impl;

import cn.com.surker.enums.StateEnum;
import cn.com.surker.production.entity.ProductionIndent;
import cn.com.surker.production.entity.vo.ProductionIndentDisVo;
import cn.com.surker.production.service.ErpIndentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * erp中的任务单实现类
 *
 * @author luotao
 * @date 2024/9/13
 */
@Service
public class ErpIndentImpl extends ProductionIndentBaseImpl implements ErpIndentService {

	@Override
	public int delete(Long indentId) {
		if (indentId == null) {
			return -1;
		}
		UpdateWrapper<ProductionIndent> uw = new UpdateWrapper<>();
		uw.eq("id", indentId);
		uw.set("status", StateEnum.DISABLED.getCode());
		int update = indentDao.update(null, uw);
		return update;
	}

	@Override
	public int updateIndentPro(List<Long> indentIds, Integer type, Integer isPro) {
		if (indentIds == null || indentIds.isEmpty() || type == null) {
			return -1;
		}
		UpdateWrapper<ProductionIndent> uw = new UpdateWrapper<>();
		uw.in("id", indentIds);
		uw.eq("status", StateEnum.ENABLED.getCode());
		/*if (ProTypeEnum.WORK.getCode().equals(proType)) {
			//	表示开盘
			uw.isNotNull("actual_start_time").set("actual_start_time", new Date());
		}*/
		//	uw.eq("type", ProTypeEnum.WAIT.getCode());
		uw.set("type", type);
		if (isPro != null) {
			uw.set("is_pro", isPro);
		}
		int update = indentDao.update(null, uw);
		return update;
	}


	@Override
	public List<ProductionIndentDisVo> dispatchList(String erpDb, List<Integer> proTypes) {
		QueryWrapper<ProductionIndent> qw = new QueryWrapper<>();
		qw.eq("a.status", StateEnum.ENABLED.getCode());
		if (proTypes != null) {
			qw.in("a.type", proTypes);
		}
		qw.groupBy("a.id");
		List<ProductionIndentDisVo> list = indentDao.dispatchList(erpDb, qw);
		return list;
	}
}
